package exceptionneverthrown;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import exceptionneverthrown.ExceptionNeverThrownMatch;
import exceptionneverthrown.ExceptionNeverThrownMatcherFactory;
import exceptionneverthrown.ExceptionNeverThrownMatcher;

public class ExceptionNeverThrownConstraint extends Constraint<ExceptionNeverThrownMatch> {

	private ExceptionNeverThrownMatcherFactory matcherFactory;

	public ExceptionNeverThrownConstraint() {
		matcherFactory = new ExceptionNeverThrownMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "Dude, $ex.name$ is never thrown by a business service!";
	}

	@Override
	public EObject getLocationObject(ExceptionNeverThrownMatch signature) {
		Object location = signature.get("ex");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("warning");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<ExceptionNeverThrownMatch, ExceptionNeverThrownMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
